package com.agile.leetcode.rmi.client;

import com.agile.leetcode.rmi.service.IService;

import javax.naming.Context;
import javax.naming.InitialContext;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/12/27 22:47
 */
public class Client {
    public static void main(String[] args) {
        String url = "rmi://localhost:1099/";
        try {
            Context namingContext = new InitialContext();
            // 强转
            IService lookup = (IService) namingContext.lookup(url + "service");
            Class<? extends IService> clazz = lookup.getClass();
            System.out.println(clazz);
            Class<?>[] interfaces = clazz.getInterfaces();
            for (Class<?> classs : interfaces) {
                System.out.println(classs.getName());
            }
            System.out.println(lookup.service("czk"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
